public class LSingle {
    public static void main(String[] args) {
        //6.创建对象进行测试
        MySingle s1 = MySingle.getSingle();
        MySingle s2 = MySingle.getSingle();
        System.out.println( s1 == s2 );//true,比较的是地址值,说明是同一个对象
        System.out.println( s1 );//cn.tedu.single.MySingle2@1b6d3586
        System.out.println( s2 );//cn.tedu.single.MySingle2@1b6d3586




    }


    static class MySingle{
        //私有化构造方法
        private MySingle(){}

        static private MySingle single;


       synchronized public static MySingle getSingle() {

           synchronized (MySingle.class){


               if (single == null) {

              single=new MySingle();//对象不存在就给它创建一个对象
               }
               return single; //有就返回
           }



        }
    }


}
